/**      
 * @file		mixedpassing.cpp
 * @description		This example demonstrates passing variables by
 *			reference and passing variables by value in the 
 *			same function.
 * @course		CSCI 123 Section 00000
 * @assignment		Sample 4
 * @date		mm/dd/yyyy
 * @author		Brad Rippe (00000000) brippe@fullcoll.edu
 * @version		1.0
 */
#include <iostream>
#include <cstdlib>
using namespace std;

/**
 * This function attempts to set the values of submarines
 * and torpedoes. 
 * @param aSubmarines the variable for submarines
 * @param aTorpedos the variable for torpedoes
 * @param aDepthCharges the number of depth charges dropped on the sub
 * @pre the arguments have been initialized to some values
 * @post the arguments are the same values that were sent to the function
 */
void getSubmarines(int& aSubmarines, int& aTorpedos, int aDepthCharges);

/**
 * @return zero if the application executes successfully
 */
int main() {
	int submarines 		= 0;
	int torpedoes 		= 0;
	int depthCharges 	= 10;
	cout << "Type the number of submarines and torpedoes\n";
	getSubmarines(submarines, torpedoes, depthCharges);
	cout << "Each sub has " << torpedoes << endl;
	cout << "with " << depthCharges << " in the water!\n";
	cout << "There are only " << submarines << " left after charges!\n";
	return 0;
}

void getSubmarines(int& aSubmarines, int& aTorpedos, int aDepthCharges) {
	
	cin >> aSubmarines;
	cin >> aTorpedos;
	cout << "You have typed ";
	cout << aSubmarines << " submarines and ";
	cout << aTorpedos << " torpedoes\n";
	
	// This code should be moved to another function
	// for brevity I'll leave it in getSubmarines
	for(int i = 0; i < aDepthCharges && 0 < aSubmarines; i++) {
		// to produce integers in the range of
		// 0 - 9, we mod by 10
		// multiplying the submarines by 2 adds some
		// variability that the depth charge may miss
		// the submarine
		int hitSub = 1 + rand() % (aSubmarines * 2);
		if(hitSub <= aSubmarines) {
			cout << "Submarine " << hitSub << " has been hit by ";
			cout << "a depth charge\n";
			aSubmarines--;
		} else {
			cout << "Depth charge " << (i+1) << " missed.\n";
		}
	}
}
